package com.bluesky.plum.uimodels.render.html.components;

import com.bluesky.javawebbrowser.domain.html.HtmlPage;
import com.bluesky.javawebbrowser.domain.html.tags.Tag;
import com.bluesky.javawebbrowser.domain.html.tags.TagType;
import com.bluesky.javawebbrowser.domain.html.tags.form.input.Text;
import com.bluesky.javawebbrowser.domain.html.tags.table.TR;
import com.bluesky.plum.richdomain.RichDomainField;

/**
 * the core domain model is POJO. the rich domain object can be converted to and
 * from the POJO model. So, we want the UI change will automatically update the
 * POJO model through the rich domain model.
 * 
 * @author HZ00260
 * 
 */
public class HSpinBox extends
		com.bluesky.plum.uimodels.standard.components.SpinBox {

	private Text textbox;

	public HSpinBox(RichDomainField field) {
		super(field);

	}

	@Override
	public void initialize() {
		super.initialize();

		if (template != null && template.length() > 0) {
			HtmlPage page = new HtmlPage(template);
			textbox = (Text) page.getRoot().getById(componentType.toString());
		} else {
			textbox = new Text();
		}
		textbox.setId(getField().name);
		textbox.setName(getField().name);
		textbox.setValue(String.format("%s", getField().value));

	}

	@Override
	public Object getNativeComponent() {

		return textbox;
	}

	@Override
	public Integer getValue() {
		return Integer.valueOf(textbox.getValue());

	}

	@Override
	public void setValue(Integer value) {

		textbox.setValue(value.toString());
	}
}
